const xml2js = require('xml2js');
const fs = require('fs');

var xmlParse = xml2js.Parser();
var xmlBdr = new xml2js.Builder();//将json转成xml语句

var readXml = fs.createReadStream('city.xml');
var data = '';

readXml.on('data', function (rs) {
    data += rs;
    xmlParse.parseString(data, function (err, result) {
        if (err) throw err;
        var res = JSON.stringify(result);
        var writeXml = fs.createWriteStream('city.json');
        writeXml.write(res);
        writeXml.end();

        //将json转成xml语句
        var xml = xmlBdr.buildObject(result);
        var writeXml = fs.createWriteStream('cityCopy.xml');

    });
});

//以上是将xml转变成json文档； 怎么将json转成xml？